#include <bits/stdc++.h>
using namespace std;
const int MAx = 300300;
int P[MAx];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &P[i]);
  vector<pair<char, int>> v;
  for (int i = 1; i < n; ++i) {
    if (P[i] < P[i + 1]) {
      if (v.empty() || v.back().first == '>')
        v.push_back(make_pair('<', 1));
      else
        v.back().second++;
    } else {
      if (v.empty() || v.back().first == '<')
        v.push_back(make_pair('>', 1));
      else
        v.back().second++;
    }
  }
  long long ans = 0;
  int size = v.size();
  for (int i = 1; i < size - 1; ++i)
    if (v[i].first == '>')
      ans += 1LL * v[i - 1].second * v[i + 1].second;
  printf("%lld\n", ans);
  return 0;
};